package org.wcms.surrounded.persistence;

import org.wcms.surrounded.model.KeyValuePair;

import com.google.inject.Inject;
import com.googlecode.objectify.Objectify;

public class KeyValueService {

    private Objectify service;
    
    @Inject
    public KeyValueService(Objectify service) {
        this.service = service;
    }
    
    public void put(String key, String value) {
        KeyValuePair pair = new KeyValuePair();
        pair.setKey(key);
        pair.setValue(value);
        service.put(pair);
    }
    
    public String get(String key) {
        KeyValuePair pair =  service
                .query(KeyValuePair.class)
                .filter("key", key).get();
        
        return pair != null ? pair.getValue() : null;
    }
    
}
